/******************************************************************************
 *
 * @file       main.cpp
 * @brief      展示同步效果
 *
 * @author     xiYan
 * @date       2025/06/07
 * @history
 *****************************************************************************/
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
#include <QTimer>

void test()
{
    qInfo() << "Testing " << QThread::currentThread();
}

// 1.示例1
/*
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QThread::currentThread()->setObjectName("Main Thread");

    qInfo() << "Starting" << QThread::currentThread();
    test();
    qInfo() << "Finished" << QThread::currentThread();


    return a.exec();
}
*/

// 2.示例2
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QThread::currentThread()->setObjectName("Main Thread");

    qInfo() << "Starting" << QThread::currentThread();
    QTimer timer;
    // 这里使用定时器延迟3秒执行test函数，看起来是一个异步的效果，但是还是在一个线程下调用
    // singleShot这个函数只执行一次！
    timer.singleShot(3000,&test);
    qInfo() << "Finished" << QThread::currentThread();


    return a.exec();
}

